<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>diyishou </title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //
        <!--业务编码、集装箱号、合同协议号、提运单号、进出口类型、收发货人、供应商、下单人-->
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [
                {
                    name: "name",
                    label: "公司名"
                }, {
                    name: "gsType",
                    label: "公司类型",
                    type: "dropdown",
                    data: [["全部", ""], ["代录单人", "1"],["隐性客户", "0"], ["客户", "2"],["混合客户", "9"]]
                },
                 {
                    name: "ctimeStart",
                    label: "申请时间起",
                    type: 'date',
                    validate: 'validate[required]'
                },
                {
                    name: "ctimeEnd",
                    label: "申请时间止",
                    type: 'date',
                    validate: 'validate[required]'
                },{
                    name: "uniteCode",
                    label: "同一社会信用代码"
                }],
            buttons: {
                custom: [
                    {
                        id: "updatebtn2",
                        value: "转换公司类型",
                        click: function () {
                            var id = getSelectedRowById('tgrid');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tgrid").getRowData(id);

                            //判断是否隐性客户，是就提示不能转换
                            if(row.gsType=="隐性客户"){
                                layer.alert("隐性客户不能转换");
                                return;
                            }
                            openViewWin(row);
                        }
                    }
                ]
            },
            grid: {
                id: "tgrid",
                title: "查询结果",
                url: "/business/cominfo/getComInfoChangeData",
                colModel: [
                    {
                        label: '主键',
                        index: "comInfoId",
                        name: "comInfoId",
                        key: true
                    },
                    {label: '公司名称', name: 'name', sortable: false},
                    {label: '公司类型', name: 'gsType', index: 'gsType',
                        formatter: function (value, options, row) {
                            if (row.isDrectCust == "0") {//隐性客户
                                return "隐性客户";
                            } else if (row.isDrectCust == "9") {//混合型客户
                                return "混合型客户";
                            } else if(row.isDrectCust == "1"){//根据逻辑判断
                                if(row.type=="CL" && row.isAgent=="1"){
                                    return "代录单人";
                                }else if(row.type=="CL" && row.isAgent=="0"){
                                    return "客户";
                                }else{
                                    return "未知类型";
                                }
                            }else {
                                return "未知状态";
                            }
                        }
                    },
                    {label: '同一社会信用代码', name: 'uniteCode', index: 'uniteCode'},
                    {label: '海关企业注册代码', name: 'customsCode', index: 'customsCode'},
                    {label: '注册时间', name: 'ctime', index: 'ctime'},
                    {label: '公司主键', name: 'comId', index: 'comId',hidden:true}
                    ],
                multiselect: true
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            doResize();
            $(window).resize(function () {
                doResize();
            });

            $(".ui-jqgrid-title").text("客户信息列表");
        });

        function doResize() {
            var ss = getPageSize();
            $("#tgrid").jqGrid('setGridHeight', ss.WinH - 270);
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }
            return {WinW: winW, WinH: winH};
        }

        //选择多条记录
        function getSels(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            return grid.getGridParam("selarrrow");
        }

        //选择一条记录
        function getSelectedRowById(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            var selectedIDs = grid.getGridParam("selarrrow");
            if (selectedIDs.length > 1) {
                alert("只能选择一条记录");
                return;
            }

            return selectedIDs[0];
        }

        /**
         * 打开窗口显示数据
         * @author han
         * */
        function openViewWin(data){
            clearForm();
            initChangeValue(data);
            layer.open({
                type: 1,
                area: ['600px', '400px'],
                title: false,
                maxmin: false, //开启最大化最小化按钮
                resize: false,
                content: $("#winContent"),
                btn: ['确定', '关闭'],
                yes: function (index, layero) {
                    var param = {};
                    param.comInfoId = $('#infoId').val();
                    param.gsType = $('#gsType').val();
                    var url = "/business/cominfo/changeCompanyType";

                    $.ajax({
                        type: "POST",
                        url: url,
                        data: param,
                        success: function (r) {
                            if (r.error_code == 0) {
                                $("#tgrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                            layer.closeAll();
                        }
                    });
                },
                cancel: function (index) {
                    clearForm();
                }
            });
        }

        /**
         * 赋值
         * @auhtor han
         * */
        function initChangeValue(data){
            $('#name').text(data.name);
            $('#uniteCode').text(data.uniteCode);
            $('#customsCode').text(data.customsCode);
            $('#infoId').val(data.comInfoId);

            var objSelect = document.getElementById('gsType');
            for (var i = 0; i < objSelect.options.length; i++) {
                if (objSelect.options[i].text == data.gsType) {
                    objSelect.options[i].selected = true;
                    break;
                }
            }
        }

        /**
         * 弹出窗口初始化
         * @author han
         **/
        function clearForm() {
            $('#name').text('');
            $('#customsCode').text('');
            $('#uniteCode').text('');
            $('#infoId').val('');
            $("#gsType").get(0).selectedIndex=0;
        }

    </script>
</head>
<body>
<div id="table"></div>
<div id="winContent" style="display:none;margin:5px 5px 5px 5px;">
    <fieldset id="mf_container0" class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
        <div class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header"><a
                href="javascript:void(0)" class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                class="ui-icon ui-icon-circle-triangle-s"></span> </a><span class="replace-ui-jqgrid-title">联系人信息</span>
        </div>
        <table class="mrdTable" style="width: 100%;">
            <tbody>
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="2" cellpadding="0" height="280px">
                        <tr>
                            <td width="150px" align="right" height="35">公司名称：</td>
                            <td>
                                <span id="name" name="name"></span>
                                <input type="hidden" id="infoId" name="infoId"/>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" height="35">同一社会信用代码：</td>
                            <td><span id="uniteCode" name="uniteCode"></span></td>
                        </tr>
                        <tr>
                            <td align="right" height="35">海关企业注册代码：</td>
                            <td><span id="customsCode" name="customsCode"></span></td>
                        </tr>
                        <tr>
                            <td align="right" height="35">公司类型：</td>
                            <td>
                                <select name="gsType" id="gsType" style="width:120px">
                                    <option value="1">代录单人</option>
                                    <option value="2">客户</option>
                                    <option value="9">混合客户</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
    </fieldset>
</div>
</body>
</html>
